<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .farther {
            width: 500px;
            height: 500px;
            background-color: red;
        }

        .son {
            width: 200px;
            height: 200px;
            background-color: skyblue;
        }
    </style>
</head>

<body>
    <div class="farther">
        <div class="son"></div>
    </div>
    <script>
        // mouseenter和mouseleave
        // mouseover和mouseout存在事件冒泡, 鼠标经过与离开子元素时也会触发事件,如果当父元素存在多个子元素时, 事件频繁触发
        // 增加负担,所以建议使用mouseenter和mouseleave
        // document.querySelector(".farther").addEventListener("mouseover", function () {
        //     console.log("鼠标经过")
        // })
        // document.querySelector(".farther").addEventListener("mouseout", function () {
        //     console.log("鼠标离开")
        // })
        document.querySelector(".farther").addEventListener("mouseenter", function () {
            console.log("鼠标经过")
        })
        document.querySelector(".farther").addEventListener("mouseleave", function () {
            console.log("鼠标离开")
        })

    </script>
</body>

</html>